package com.jike.noobmoney.adapter;


import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.jike.noobmoney.R;
import com.jike.noobmoney.contants.ConstantValue;
import com.jike.noobmoney.entity.MyTaskEntity;
import com.jike.noobmoney.mvp.view.activity.MyTousuActivity;


/**
 * Created by kekex on 2018/9/8.
 * 我的任务的列表adapter
 */

public class MyTaskListAdapter extends BaseRecyclerAdapter<MyTaskEntity.OrderlistBean> {


    private Context context;

    public MyTaskListAdapter(Context context) {

        super(R.layout.item_my_task_list);
        this.context = context;

    }

    @Override
    protected void onBindViewHolder(SmartViewHolder holder, MyTaskEntity.OrderlistBean item, int position) {

        ImageView imageView = (ImageView) holder.findViewById(R.id.iv_img);
        if (!TextUtils.isEmpty(item.getPicture())) {
            RoundedCorners roundedCorners = new RoundedCorners(14);
            RequestOptions options = RequestOptions.bitmapTransform(roundedCorners);
            Glide.with(context).load(ConstantValue.IMG_BASEURL + item.getPicture()).apply(options).into(imageView);
        } else {
            imageView.setImageResource(R.mipmap.ic_launcher);
        }
        holder.text(R.id.tv_title, TextUtils.isEmpty(item.getTaskname()) ? "小白赚钱" : item.getTaskname());
        holder.text(R.id.tv_finish, "已完成"+item.getFinishnumber() + "份");
        holder.text(R.id.tv_remain, "剩余" + item.getLastnumber() + "份");
        holder.text(R.id.tv_money, "" + item.getMoney());

        TextView viewById = (TextView) holder.findViewById(R.id.tv_shibai);
        TextView tousu = (TextView) holder.findViewById(R.id.tv_tousu);
        TextView tv_reason = (TextView) holder.findViewById(R.id.tv_reason);

        if (item.getStatus() == 2||item.getStatus()==5) {
            if(item.getStatus()==2) {
                tv_reason.setVisibility(View.VISIBLE);
                holder.text(R.id.tv_reason, "失败原因:" + (TextUtils.isEmpty("" + item.getFalsetext()) ? "无" : item.getFalsetext()));
            }else if(item.getStatus()==5)
            {
                tv_reason.setVisibility(View.VISIBLE);
                viewById.setVisibility(View.GONE);
                holder.text(R.id.tv_reason, "投诉原因:" + (TextUtils.isEmpty("" + item.getAtext()) ? "无" : item.getAtext()));
            }
            } else {
            tv_reason.setVisibility(View.GONE);
        }
        int status=item.getStatus();
        if(status==1){
            viewById.setVisibility(View.VISIBLE);
            viewById.setText(item.canceltime+"前请提交，超时自动取消");
        }else if(status==2)
        {
            viewById.setVisibility(View.VISIBLE);
            viewById.setText("请于"+item.canceltime+"前重新提交，超时自动取消");
        }else if(status==3)
        {
            viewById.setVisibility(View.VISIBLE);
            viewById.setText("最晚将于"+item.passtime+"前完成审核，请耐心等待");

        }else if(status==4)
        {
            viewById.setVisibility(View.VISIBLE);
            viewById.setText(" 该任务已在"+item.getFinishtime()+"完成");
        }
        tousu.setOnClickListener(v -> {
            Intent intent = new Intent(context, MyTousuActivity.class);
            intent.putExtra("o_id", "" + item.getO_id());
            context.startActivity(intent);
        });
    }
}
